<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    
<%@page import="java.sql.*,java.util.*" %>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Degree Location</title>
</head>
<body>

<%
	String radio1Param = request.getParameter("permanentResident");

	String streetParam = request.getParameter("street");
	String cityParam = request.getParameter("city");
	String stateParam = request.getParameter("state");
	String countryCodeParam = request.getParameter("countryCode");
	String zipParam = request.getParameter("zip");
	String areaCodeParam = request.getParameter("areaCode");
	String phoneParam = request.getParameter("phone");

	if (streetParam != null) {
		session.setAttribute("streetSes", streetParam);
		session.setAttribute("citySes", cityParam);
		
		if (stateParam != null)
		{
			session.setAttribute("stateSes", stateParam);
		}
		else
		{
			session.setAttribute("countryCodeSes", countryCodeParam);
		}

		session.setAttribute("zipSes", zipParam);
		session.setAttribute("areaCodeSes", areaCodeParam);
		session.setAttribute("phoneSes", phoneParam);
	}
	session.setAttribute("permanentResident", radio1Param);
	Class.forName("org.postgresql.Driver");
	Connection connect = DriverManager.getConnection("jdbc:postgresql://localhost/tester?user=postgres&password=admin");
	
	PreparedStatement prepStmt;
	ResultSet rset;
	
	
	
	prepStmt = connect.prepareStatement("SELECT * FROM states");
	rset = prepStmt.executeQuery();
	Vector states = new Vector();
	Vector statesID = new Vector();
	while(rset.next())
	{
		statesID.add(rset.getString("id"));
		states.add(rset.getString("state"));
	}
	
	
	prepStmt = connect.prepareStatement("SELECT * FROM countries");
	rset = prepStmt.executeQuery();
	Vector countries = new Vector();
	Vector countryID = new Vector();
	while(rset.next())
	{
		countryID.add(rset.getString("id"));
		countries.add(rset.getString("country"));
	}

%>
	<%= session.getAttribute("firstNameSes") %>
	<%= session.getAttribute("middleInitialSes") %>
	<%= session.getAttribute("lastNameSes") %><br>
	Citizen of <%= session.getAttribute("citizenSes") %><br>
	Resident of <%= session.getAttribute("residentSes") %><br>
	Address: <%= session.getAttribute("streetSes") %><br>
	City: <%= session.getAttribute("citySes") %><br>
	<%
	if( stateParam != null )
	{ %>
		State: <%= session.getAttribute("stateSes") %><br>
	<%
	}
	else
	{ %>
		Country Code: <%= session.getAttribute("countryCodeSes") %><br>
		
	<% } %>
	Zip: <%= session.getAttribute("zipSes") %><br>
	Phone Number: (<%= session.getAttribute("areaCodeSes") %>) <%= session.getAttribute("phoneSes") %><br>
	<br>
	
	<%
	if (radio1Param != null)
	{ %>
		Domestic Status: <%= session.getAttribute("permanentResident") %><br>
	<% } %>
	<br>


	

	Where did you receive your degree?<br><br>United States<br><br>

	<div id="left_wrapper">
	<div id="left">
	<p>

	<%
	for (int i = 0; i < states.size() / 3; i++)
	{ %>
		<a href="7_DegreeUniversity.jsp?degreeCountry=<%= states.get(i) %>&stateID=<%= statesID.get(i) %>" ><%= states.get(i) %></a><br>

	<% } %>

	</p>
	</div>
	</div>

	<div id="middle_wrapper">
	<div id="left">
	<p>

	<%
	for (int i = states.size() / 3; i < 2 * (states.size() / 3); i++)
	{ %>
		<a href="7_DegreeUniversity.jsp?degreeCountry=<%= states.get(i) %>&stateID=<%= statesID.get(i)%>" ><%= states.get(i) %></a><br>

	<% } %>

	</p>
	</div>
	</div>

	<div id="right_wrapper">
	<div id="right">
	<p>
	
	<%
	for (int i = 2 * (states.size() / 3); i < states.size(); i++)
	{ %>
		<a href="7_DegreeUniversity.jsp?degreeCountry=<%= states.get(i) %>&stateID=<%= statesID.get(i)%>" ><%= states.get(i) %></a><br>

	<% } %>

	</p>
	</div>
	</div>

	

	<br><br>Countries<br><br>

	<div id="left_wrapper">
	<div id="left">
	<p>

	<%
	for (int i = 0; i < countries.size() / 3; i++)
	{ %>
		<a href="7_DegreeUniversity.jsp?degreeCountry=<%= countries.get(i) %>&countryID=<%= countryID.get(i) %>" ><%= countries.get(i) %></a><br>

	<% } %>

	</p>
	</div>
	</div>

	<div id="middle_wrapper">
	<div id="left">
	<p>

	<%
	for (int i = countries.size() / 3; i < 2 * (countries.size() / 3); i++) 
	{ %>
		<a href="7_DegreeUniversity.jsp?degreeCountry=<%= countries.get(i) %>&countryID=<%= countryID.get(i) %>" ><%= countries.get(i) %></a><br>

	<% } %>

	</p>
	</div>
	</div>

	<div id="right_wrapper">
	<div id="right">
	<p>

	<%
	for (int i = 2 * (countries.size() / 3); i < countries.size(); i++)
	{ %>
		<a href="7_DegreeUniversity.jsp?degreeCountry=<%= countries.get(i) %>&countryID=<%= countryID.get(i) %>" ><%= countries.get(i) %></a><br>

	<% } %>

	</p>
	</div>
	</div>



<br><br>

</body>
</html>